<template>
  <div class="cell" @click="showDrawer" :style="view?'border: none !important;':'cursor: pointer;'">
    <van-cell-group>
      <van-cell :title="item.title" :value="item.value" :icon="item.icon" v-for="(item,index) in props.cell" :key="index" >
        <template slot="label" v-if="item.label">
          {{item.label}}
        </template>
        <template slot="icon">
          <a-icon v-if="item.icon" :type="item.icon" :style="{ fontSize: '18px',marginTop:'4px',marginRight:'5px'}" />
        </template>
      </van-cell>
    </van-cell-group>
    <drawer :attr="list.attr" :show.sync="show" @change="editAttr" :index="list.index" />
  </div>
</template>

<script>
import drawer from "../drawer"
import changeAttr from '@/utils/changeAttr.js'
import changeViewAttr from '@/utils/changeViewAttr.js'

export default {
  components:{
    drawer
  },
  name:"cell",
  props:{
    list:{
      type:Object,
    },
    view:{
      type:Boolean,
      default:false
    }
  },
  data() {
    return {
      show:false,
      props:{},
      changeAttr,
    }
  },
  created() {
    this.editAttr()
  },
  methods: {
    showDrawer(){
      if(!this.view){
        this.show = true
      }
    },
    editAttr(){
      if(this.view){
        this.props = changeViewAttr(this.list.attr,this.list.index)
      }else{
        this.props = changeAttr(this.list.attr,this.list.index)
      }
    }
  },
}
</script>

<style scoped>
  .cell{
    box-sizing: border-box;
    border: 1px dashed transparent;
  }
  .cell:hover{
    border: 1px dashed #1989fa;
  }
  .cell >>> .van-hairline--top-bottom::after{
    border-width: 0 0;
  }
</style>